/**
 * 数据分页类
 * @version 1.0.0-beta.220310
 */
class EsPagination {
	// 选项
	_option = {
		page: 0,
		pageSize: 10,
		pageCount: 0,
		total: 0,
		status: 1,
		message: "",
	}
	// 构造方法
	construct(pageId, pageSize, total) {
		this._option.page = pageId;
		this._option.pageSize = pageSize;
		if (total > 0 && pageSize > 0) {
			this._option.pageCount = Math.ceil(total / pageSize);
		}
	}
	// 静态实例集合
	static instances = {};
	// 创建实例
	static create(name, pageId, pageSize, total) {
		if (EsPagination.instances[name]) {
			return EsPagination.instances[name];
		}
		EsPagination.instances[name] = new EsPagination(pageId, pageSize, total);
	}
	// 返回实例
	static getInstance(name) {
		return EsPagination.instances[name];
	}
	// 下一页
	nextPage() {
		if (this._option.pageCount == 0) {
			this._option.status = 0;
			this._option.message = "没有数据";
			return this._option;
		}
		if (this._option.page == this._option.pageCount) {
			this._option.status = 0;
			this._option.message = "已经是最后一页了";
			return this._option;
		}
		if (this._option.pageCount > 0 && this._option.pageCount > this._option.page) {
			this._option.page++;
		}
		return this._option;
	}
	// 上一页
	prevPage() {
		if (this._option.pageCount == 0) {
			this._option.status = 0;
			this._option.message = "没有数据";
			return this._option;
		}
		if (this._option.page <= 1) {
			this._option.status = 0;
			this._option.message = "已经是第一页了";
			return this._option;
		}
		if (this._option.page > 1) {
			this._option.page--;
		}
		return this._option;
	}
}

export default EsPagination;
